package com.guangdujs.kis.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.date.DateUtil;
import com.guangdujs.kis.domain.vo.PieChartData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.guangdujs.kis.mapper.Vwicbill32Mapper;
import com.guangdujs.kis.domain.Vwicbill32;
import com.guangdujs.kis.service.IVwicbill32Service;

/**
 * 销售订单Service业务层处理
 * 
 * @author kis
 * @date 2022-11-04
 */
@Service
public class Vwicbill32ServiceImpl implements IVwicbill32Service
{
    @Autowired
    private Vwicbill32Mapper vwicbill32Mapper;

    /**
     * 查询销售订单列表
     */
    @Override
    public List<Vwicbill32> selectVwicbill32List(Vwicbill32 vwicbill32)
    {
        return vwicbill32Mapper.selectVwicbill32List(vwicbill32);
    }

    @Override
    public BigDecimal selectAllAmount(Vwicbill32 vwicbill32) {
        return vwicbill32Mapper.selectAllAmount(vwicbill32);
    }

    @Override
    public List<String> selectFcustidnameList(Vwicbill32 vwicbill32) {
        return vwicbill32Mapper.selectFcustidnameList(vwicbill32);
    }

    @Override
    public List<String> selectFmangeridnameList(Vwicbill32 vwicbill32) {
        return vwicbill32Mapper.selectFmangeridnameList(vwicbill32);
    }

    @Override
    public List<String> selectFempidnameList(Vwicbill32 vwicbill32) {
        return vwicbill32Mapper.selectFempidnameList(vwicbill32);
    }

    @Override
    public List<String> selectFitemnameList(Vwicbill32 vwicbill32) {
        return vwicbill32Mapper.selectFitemnameList(vwicbill32);
    }

    @Override
    public Map<String, BigDecimal> selectFourMoney() {
        Map<String, BigDecimal> fourMoneyMap = new HashMap<>();

        // 1、当日销售额
        BigDecimal todayMoney = vwicbill32Mapper.selectTodayMoney();
        // 2、当月销售额
        BigDecimal monthMoney = vwicbill32Mapper.selectOneMonthMoney();
        // 3、当季销售额
        BigDecimal quarterMoney = vwicbill32Mapper.selectQuarterMoney();
        // 4、当年销售额
        BigDecimal yearMoney = vwicbill32Mapper.selectYearMoney();

        fourMoneyMap.put("todayMoney", todayMoney);
        fourMoneyMap.put("monthMoney", monthMoney);
        fourMoneyMap.put("quarterMoney", quarterMoney);
        fourMoneyMap.put("yearMoney", yearMoney);

        return fourMoneyMap;
    }

    @Override
    public Map<String, Object> selectMonthMoneyList() {
        Map<String, Object> monthMoneyMap = new HashMap<>();

        List<String> xData = new ArrayList<>();
        for(int i=0; i<DateUtil.lengthOfMonth(DateUtil.thisMonth()+1, DateUtil.isLeapYear(DateUtil.thisYear())); i++){
            xData.add((i+1)+"号");
        }
        monthMoneyMap.put("xData", xData);

        List<BigDecimal> yData = new ArrayList<>();
        for(int i=0; i<DateUtil.lengthOfMonth(DateUtil.thisMonth()+1, DateUtil.isLeapYear(DateUtil.thisYear())); i++){
            BigDecimal monthMoney = vwicbill32Mapper.selectMonthMoney(DateUtil.formatDate(DateUtil.offsetDay(DateUtil.beginOfMonth(DateUtil.date()),i)));
            yData.add(monthMoney);
        }
        monthMoneyMap.put("yData", yData);

        return monthMoneyMap;
    }

    @Override
    public Map<String, Object> selectQuarterMoneyList() {
        Map<String, Object> quarterMoneyMap = new HashMap<>();
        List<String> xData = new ArrayList<>();
        List<BigDecimal> yData = new ArrayList<>();
        switch(DateUtil.quarter(DateUtil.date())){
            case 1 :
                xData.add("01月份");
                xData.add("02月份");
                xData.add("03月份");
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-01-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-01-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-02-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-02-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-03-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-03-01")))));
                break;
            case 2 :
                xData.add("04月份");
                xData.add("05月份");
                xData.add("06月份");
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-04-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-04-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-05-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-05-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-06-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-06-01")))));
                break;
            case 3 :
                xData.add("07月份");
                xData.add("08月份");
                xData.add("09月份");
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-07-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-07-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-08-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-08-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-09-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-09-01")))));
                break;
            default :
                xData.add("10月份");
                xData.add("11月份");
                xData.add("12月份");
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-10-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-10-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-11-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-11-01")))));
                yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-12-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-12-01")))));
        }
        quarterMoneyMap.put("xData", xData);
        quarterMoneyMap.put("yData", yData);
        return quarterMoneyMap;
    }

    @Override
    public Map<String, Object> selectYearMoneyList() {
        Map<String, Object> yearMoneyMap = new HashMap<>();
        List<String> xData = new ArrayList<>();
        List<BigDecimal> yData = new ArrayList<>();
        xData.add("01月份");
        xData.add("02月份");
        xData.add("03月份");
        xData.add("04月份");
        xData.add("05月份");
        xData.add("06月份");
        xData.add("07月份");
        xData.add("08月份");
        xData.add("09月份");
        xData.add("10月份");
        xData.add("11月份");
        xData.add("12月份");
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-01-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-01-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-02-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-02-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-03-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-03-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-04-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-04-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-05-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-05-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-06-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-06-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-07-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-07-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-08-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-08-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-09-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-09-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-10-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-10-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-11-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-11-01")))));
        yData.add(vwicbill32Mapper.selectScopeMoney(DateUtil.formatDate(DateUtil.beginOfMonth(DateUtil.parse(DateUtil.thisYear() + "-12-01"))), DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parse(DateUtil.thisYear() + "-12-01")))));
        yearMoneyMap.put("xData", xData);
        yearMoneyMap.put("yData", yData);
        return yearMoneyMap;
    }

    @Override
    public List<PieChartData> selectTopFItemNames() {
        return vwicbill32Mapper.selectTopFItemNames();
    }

    @Override
    public List<PieChartData> selectTopFCustIDNames() {
        return vwicbill32Mapper.selectTopFCustIDNames();
    }

    @Override
    public List<PieChartData> selectTopProvince() {
        return vwicbill32Mapper.selectTopProvince();
    }
}
